package de.koller.worlders.engine.entity.mo;

import de.koller.oceanFramework.tree.Mother;
import de.koller.worlders.WSea;
import de.koller.worlders.engine.entity.zone.Zone;
import java.util.HashSet;
import java.util.Set;

public class MOZoneHandler extends WSea {

	private final Set<Zone> currIn = new HashSet<>();
	@Mother private MovingObject mo;

	public void step( Set<Zone> in ) {
		
		Set<Zone> toR = new HashSet<>();
		for( Zone z : currIn ) {
			if( in.contains( z ) )
				in( z );
			else {
				toR.add( z );
				leave( z );
			}
		}
		
		currIn.removeAll( toR );
		
		for( Zone z : in ) {
			if( !currIn.contains( z ) ) {
				currIn.add( z );
				enter( z );
			}
		}
			
	}

	public void enter( Zone z ) {
		z.enter( mo );
	}
	
	public void in( Zone z ) {
		z.in( mo );
	}
	
	public void leave( Zone z ) {
		z.leave( mo );
	}
	
}
